package io.renren.modules.sys.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.modules.sys.dao.ShelvesStockDao;
import io.renren.modules.sys.entity.OnshelvesStatisticsEntity;
import io.renren.modules.sys.entity.ShelvesStockStatisticsEntity;
import io.renren.modules.sys.entity.ShelvesStockEntity;
import io.renren.modules.sys.service.ShelvesStockService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("shelvesstockService")
public class ShelvesStockServiceImpl extends ServiceImpl<ShelvesStockDao, ShelvesStockEntity> implements ShelvesStockService {


    /**
     * 查询库存信息
     * @param params 查询参数
     */
    @Override
    public PageUtils queryListPage(Map<String, Object> params){
        int pageSize = Integer.parseInt(params.get("limit").toString());  //每页记录数
        int currPage = Integer.parseInt(params.get("page").toString());  //当前页数

        String name = null;
        if( params.get("name")!=null&&!params.get("name").equals("")){
            name = params.get("name").toString();
        }

        String groupid = null;
        if( params.get("group")!=null&&!params.get("group").equals("")){
            groupid = params.get("group").toString();
        }
        Integer shelvesid = 0;
        if( params.get("shelvesid")!=null&&!params.get("shelvesid").equals("")){
            shelvesid = Integer.parseInt(params.get("shelvesid").toString());
        }
        int count = baseMapper.queryListcount(name,groupid,shelvesid);
        List<ShelvesStockEntity> list = baseMapper.queryListPage(name,groupid,shelvesid,(currPage-1)*pageSize,currPage*pageSize);
        return new PageUtils(list,count,pageSize,currPage);
    }

    @Override
    public ShelvesStockStatisticsEntity getStatistics(Map<String, Object> params){
        String name = null;
        if( params.get("name")!=null&&!params.get("name").equals("")){
            name = params.get("name").toString();
        }

        String groupid = null;
        if( params.get("group")!=null&&!params.get("group").equals("")){
            groupid = params.get("group").toString();
        }
        Integer shelvesid = 0;
        if( params.get("shelvesid")!=null&&!params.get("shelvesid").equals("")){
            shelvesid = Integer.parseInt(params.get("shelvesid").toString());
        }
        ShelvesStockStatisticsEntity shelvesStockStatisticsEntity = baseMapper.getStatistics(name,groupid,shelvesid);

        return shelvesStockStatisticsEntity;
    }

}
